<template>
  <div class="market-page">
    <!-- 顶部导航栏 -->
    <div class="market-header">
      <div class="header-left">
        <svg class="back-arrow" viewBox="0 0 24 43" @click="goBack">
          <path d="M20 2 L4 21.5 L20 41" stroke="#222" stroke-width="4" fill="none" stroke-linecap="round"/>
        </svg>
      </div>
      <div class="header-title">友好市集goodmart</div>
      <div class="header-search">
        <div class="search-box">
          <svg class="search-icon" viewBox="0 0 24 24">
            <circle cx="11" cy="11" r="8" stroke="#bbb" stroke-width="2" fill="none"/>
            <line x1="18" y1="18" x2="22" y2="22" stroke="#bbb" stroke-width="2" stroke-linecap="round"/>
          </svg>
          <input type="text" placeholder="黑曜石" />
          <span class="search-divider"></span>
          <button>搜索</button>
        </div>
      </div>
    </div>
    <!-- 二级导航菜单 -->
    <div class="market-nav-bar">
      <div class="market-nav-item" v-for="item in navList" :key="item.text" @click="handleNavClick(item)">
        <svg class="market-nav-icon">
          <use :xlink:href="item.icon"></use>
        </svg>
        <div class="market-nav-text">{{ item.text }}</div>
      </div>
    </div>
    <!-- 商品列表 -->
    <div class="market-goods-list">
      <div class="goods-card" v-for="item in goodsList" :key="item.id" @click="goDetail(item)">
        <div class="goods-img-wrap">
          <img :src="item.img" class="goods-img" />
        </div>
        <div class="goods-info">
          <div class="goods-title">{{ item.title }}</div>
          <div class="goods-subtitle" v-if="item.subtitle">{{ item.subtitle }}</div>
          <div class="goods-price-row">
            <span class="goods-price">￥{{ item.price }}</span>
            <span class="goods-old-price" v-if="item.oldPrice">￥{{ item.oldPrice }}</span>
            <span class="goods-sold" v-if="item.sold">已售{{ item.sold }}</span>
          </div>
          <div class="goods-tags" v-if="item.tags && item.tags.length">
            <span class="goods-tag" v-for="tag in item.tags" :key="tag">{{ tag }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Market',
  data() {
    return {
      goodsList: [
        {
          id: 1,
          img: require('/public/img/shop/shop (1).gif'),
          title: '真零·酸奶1KG桶装发酵风味低温酸奶营养',
          subtitle: '生牛乳>99.9% 添加7种有益菌',
          price: '29.9',
          oldPrice: '39.9',
          sold: '5万+',
          tags: ['限时立减10', '假一赔四']
        },
        {
          id: 2,
          img:  require('/public/img/shop/shop (2).gif'),
          title: '福保罗·夏季男生穿搭夏天干净短袖套装搭配t',
          subtitle: '八套简单干净韩系穿搭',
          price: '149.52',
          oldPrice: '178',
          sold: '2',
          tags: ['限时立减28.48', '3期免息']
        },
        {
          id: 3,
          img:  require('/public/img/shop/shop (3).gif'),
          title: '春日复古德训 chill感的秘诀',
          subtitle: '无鞋带一脚蹬',
          price: '338',
          sold: '308',
          tags: []
        },
        {
          id: 4,
          img: require('/public/img/shop/shop (5).gif'),
          title: '纯色排汗速干背心男跑步训练休闲透气素肤速',
          subtitle: '',
          price: '16.91',
          oldPrice: '39.9',
          sold: '2588',
          tags: ['限时立减9.3', '3期免息']
        },
        {
          id: 5,
          img: require('/public/img/shop/shop (7).gif'),
          title: '挖到一只宝藏户外登山包！',
          subtitle: '',
          price: '95.8',
          oldPrice: '112.8',
          sold: '59',
          tags: ['限时立减9.3', '3期免息']
        },
        {
          id: 6,
          img: require('/public/img/shop/shop (6).gif'),
          title: '山尺·金丝檀木手串沉水级佛珠文玩天然和田',
          subtitle: '',
          price: '100.3',
          oldPrice: '118',
          sold: '10002',
          tags: ['限时立减17.7', '退货包运费']
        },
        {
          id: 7,
          img: require('/public/img/shop/shop (8).gif'),
          title: '旗舰店兮元记·文创陶瓷四色茶杯套装万里山河',
          subtitle: '',
          price: '74.8',
          oldPrice: '176',
          sold: '1626',
          tags: ['限时立减101.2', '退货包运费']
        },
        {
          id: 8,
          img: require('/public/img/shop/shop (9).gif'),
          title: '花儿与少年同款原创运动斜挎包男潮牌旅行包',
          subtitle: '',
          price: '36.38',
          oldPrice: '42.8',
          sold: '92',
          tags: ['限时立减6.42', '退货包运费']
        },
        {
          id: 9,
          img: require('/public/img/shop/shop (10).gif'),
          title: '磁吸手机助拍器，踏春vlog拍摄秒变单反',
          subtitle: '',
          price: '84.1',
          oldPrice: '99',
          sold: '71',
          tags: ['限时立减6.42', '退货包运费']
        },
        {
          id:10,
          img: require('/public/img/shop/shop (11).gif'),
          title: 'SHAKEAIR·sportychic时髦灰色运动七分裤',
          subtitle: '',
          price: '142.8',
          oldPrice: '168',
          sold: '78',
          tags: ['限时立减25.2', '退货包运费']
        },
      ],
      navList: [
        { icon: '#icon-dingdan', text: '我的订单' },
        { icon: '#icon-gouwuche', text: '购物车' },
        { icon: '#icon-quanbao', text: '卡券包' },
        { icon: '#icon-wodepinglun', text: '客服消息' },
        { icon: '#icon-shangdian', text: '关注店铺' },
      ]
    }
  },
  methods: {
    goBack() {
      this.$router.back();
    },
    goDetail(item) {
      const idx = this.goodsList.findIndex(g => g.title === item.title && g.img === item.img);
      const realId = idx !== -1 ? idx + 1 : item.id;
      this.$router.push(`/market/detail/${realId}`);
    },
    handleNavClick(item) {
      if (item.text === '购物车') {
        this.$router.push('/market/cart');
      } else if (item.text === '我的订单') {
        this.$router.push({ path: '/order', query: { from: 'market' } });
      }
    }
  }
}
</script>

<style scoped>
.market-page {
  background: #f7f7f7;
  min-height: 100vh;
}
.market-header {
  max-width: 750px;
  width: 100%;
  min-height: 90px;
  height: auto;
  display: flex;
  align-items: center;
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
  box-sizing: border-box;
  padding: 0;
  margin: 0 auto;
  overflow: hidden;
}
.header-left {
  width: 62px; /* 38px + 24px */
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-left: 0;
}
.back-arrow {
  width: 24px;
  height: 43px;
  margin-left: 38px;
  cursor: pointer;
  display: block;
}
.header-title {
  font-size: 38px;
  font-weight: bold;
  color: #222;
  margin-left: 30px;
  flex-shrink: 0;
}
.header-search {
  flex: 1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
  margin-left: 30px;
  margin-right: 32px;
  min-width: 0;
}
.search-box {
  display: flex;
  align-items: center;
  background: #f4f4f4;
  border-radius: 36px;
  height: 48px;
  padding: 0 12px 0 18px;
  max-width: 320px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.search-icon {
  width: 24px;
  height: 24px;
  margin-right: 8px;
  flex-shrink: 0;
}
.search-box input {
  border: none;
  outline: none;
  background: transparent;
  color: #222;
  font-size: 24px;
  flex: 1 1 0%;
  height: 48px;
  min-width: 0;
}
.search-box input::placeholder {
  color: #bbb;
  font-size: 24px;
}
.search-divider {
  display: inline-block;
  width: 1px;
  height: 28px;
  background: #e0e0e0;
  margin: 0 12px;
  vertical-align: middle;
}
.search-box button {
  background: transparent;
  border: none;
  color: #222;
  font-size: 24px;
  font-weight: 500;
  margin-left: 8px;
  cursor: pointer;
  padding: 0;
}
/* 瀑布流布局 */
.market-goods-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 0 2px;
  box-sizing: border-box;
  max-width: 750px;
  margin: 0 auto;
}
.goods-card {
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  width: 360px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.goods-img-wrap {
  width: 362px;
  height: 482px;
  overflow: hidden;
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
}
.goods-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.goods-info {
  padding: 18px 18px 0 18px;
  height: 228px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}
.goods-title {
  font-size: 27px;
  font-weight: 600;
  color: #222;
  margin-bottom: 10px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  max-height: 2.6em;
}
/* 商品副标题 */
.goods-subtitle {
  font-size: 20px;
  color: #888;
  margin-bottom: 8px;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  max-height: 2.4em;
}
/* 价格、原价、销量一行 */
.goods-price-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.goods-price {
  color: #fe2c55;
  font-size: 28px;
  font-weight: bold;
}
.goods-old-price {
  color: #bbb;
  font-size: 20px;
  text-decoration: line-through;
}
.goods-sold {
  color: #bbb;
  font-size: 18px;
}
.goods-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.goods-tag {
  background: #f5f5f5;
  color: #fe2c55;
  font-size: 18px;
  border-radius: 8px;
  padding: 2px 10px;
}
/* 二级导航菜单样式 */
.market-nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  background: #fff;
  max-width: 750px;
  width: 100%;
  margin: 0 auto;
  padding: 15px 37px 20px 37px;
  box-sizing: border-box;
}
.market-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}
.market-nav-icon {
  width: 46px;
  height: 46px;
  margin-bottom: 20px;
  display: block;
}
.market-nav-text {
  font-size: 23px;
  color: #8b8b8b;
  text-align: center;
}
</style> 